package chunmap.util.image;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageUtil {
	public static byte[] Image2ByteArray(Image image,String formatName) throws IOException{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ImageIO.write((RenderedImage) image, formatName, bos);
		return bos.toByteArray();
	}
	public static Image imageCopy(Image image,int x,int y,int w,int h){
		Image newImage=new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
		newImage.getGraphics().drawImage(image, x, y, null);
		return newImage;
	}
}
